﻿using System;
using ClientOverflow.Core;
using ClientOverflow.ViewModels.Interfaces;
using ClientOverflow.ViewModels.QuestionsListViewModels;

namespace ClientOverflow.ViewModels.MainMenus
{
    /// <summary>
    /// ShowQuestionsListCommand sets the view to showing all questions mode. This mode allows the user to browse
    /// through the existing questions and navigate to them.
    /// </summary>
    public class ShowQuestionsListCommand : INamedCommand
    {
        private readonly IMenusViewModel viewModel;
        private readonly ILoginService loginService;

        public ShowQuestionsListCommand(IMenusViewModel viewModel)
        {
            this.viewModel = viewModel;
            loginService = ServicesProviderFactory.GetInstance().LoginService;
            loginService.OnLoginChanged += (sender, args) => CanExecuteChanged(this, EventArgs.Empty);
            
        }

        public string Name
        {
            get { return "All questions"; }
        }

        public void Execute(object parameter)
        {
            viewModel.Content = new QuestionsListViewModel(viewModel, new AllQuestionsFilter());
        }

        public bool CanExecute(object parameter)
        {
            return loginService.LoggenInUser != null;
        }

        public event EventHandler CanExecuteChanged;
    }
}